# Written by DeepSeek.
# https://chat.deepseek.com/

import matplotlib.pyplot as plt
import matplotlib.patches as patches
import sys

def plot_data(filename):
    # 读取并解析文件
    with open(filename, 'r') as f:
        lines = [line.strip() for line in f.readlines() if line.strip()]

    # 解析宽度和高度
    if len(lines) < 2:
        raise ValueError("文件格式不正确")
    w_part, h_part = lines[1].split()
    W = float(w_part[1:])
    H = float(h_part[1:])

    # 解析圆的数据
    circles = []
    for line in lines[2:]:
        x_part, y_part, r_part = line.split()
        x = float(x_part[1:])
        y = float(y_part[1:])
        r = float(r_part[1:])
        circles.append((x, y, r))

    # 创建图形和坐标轴
    fig = plt.figure(figsize=(6.4, 4.8), dpi=100)
    ax = fig.add_subplot(111)
    
    # 绘制箱子边框
    rect = patches.Rectangle((0, 0), W, H, linewidth=1, 
                             edgecolor='black', facecolor='none')
    ax.add_patch(rect)
    
    # 绘制每个圆
    for x, y, r in circles:
        circle = patches.Circle((x, y), r, linewidth=1, 
                                edgecolor='blue', facecolor='none')
        ax.add_patch(circle)
    
    # 设置坐标轴范围和比例
    ax.set_xlim(0, W)
    ax.set_ylim(0, H)
    ax.set_aspect('equal')
    
    # 显示图形
    plt.show()

if __name__ == "__main__":
    if len(sys.argv) != 2:
        print("使用方式: python main.py <文件路径>")
        sys.exit(1)
    try:
        plot_data(sys.argv[1])
    except Exception as e:
        print(f"错误: {e}")
